package com.hmall.search.web;

import com.hmall.search.common.PageResult;
import com.hmall.search.pojo.ItemPageQueryDTO;
import com.hmall.search.pojo.ItemVO;
import com.hmall.search.service.IsearchService;
import lombok.RequiredArgsConstructor;
import org.elasticsearch.search.SearchService;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/search")
@RequiredArgsConstructor
public class SearchController {

    private final IsearchService searchService;

    @GetMapping("/suggestion")
    public List<String> suggestion(String key){
        return searchService.suggestion(key);
    }

    @PostMapping("/filters")
    public Map<String,List<String>> filters(@RequestBody ItemPageQueryDTO itemPageQueryDTO){
        return searchService.filters(itemPageQueryDTO);
    }

    @PostMapping("/list")
    public PageResult<ItemVO> list(@RequestBody ItemPageQueryDTO itemPageQueryDTO){
        return searchService.listPage(itemPageQueryDTO);
    }

}
